package cn.ware.house.interfaces.controller.inbountController;

import cn.ware.house.interfaces.entity.inventory.InboundProductStyle;
import cn.ware.house.interfaces.service.inboundservice.InboundProductStyleService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/inbound-product-styles")
public class InboundProductStyleController {

    private final InboundProductStyleService inboundProductStyleService;

    public InboundProductStyleController(InboundProductStyleService inboundProductStyleService) {
        this.inboundProductStyleService = inboundProductStyleService;
    }

    // 根据入库产品样式编号查询样式信息
    @GetMapping("/{id}")
    public ResponseEntity<InboundProductStyle> getInboundProductStyleById(@PathVariable Integer id) {
        InboundProductStyle inboundProductStyle = inboundProductStyleService.getInboundProductStyleById(id);
        if (inboundProductStyle!= null) {
            return new ResponseEntity<>(inboundProductStyle, HttpStatus.OK);
        } else {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    }

    // 根据入库产品编号查询该产品的所有样式信息
    @GetMapping("/by-product/{inboundProductId}")
    public ResponseEntity<List<InboundProductStyle>> getInboundProductStylesByProductId(@PathVariable Integer inboundProductId) {
        List<InboundProductStyle> inboundProductStyles = inboundProductStyleService.getInboundProductStylesByProductId(inboundProductId);
        return new ResponseEntity<>(inboundProductStyles, HttpStatus.OK);
    }

    // 插入入库产品样式信息
    @PostMapping
    public ResponseEntity<Boolean> addInboundProductStyle(@RequestBody InboundProductStyle inboundProductStyle) {
        boolean result = inboundProductStyleService.addInboundProductStyle(inboundProductStyle);
        if (result) {
            return new ResponseEntity<>(true, HttpStatus.CREATED);
        } else {
            return new ResponseEntity<>(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    // 根据入库产品样式编号更新样式信息
    @PutMapping("/{id}")
    public ResponseEntity<Boolean> updateInboundProductStyleById(@PathVariable Integer id, @RequestBody InboundProductStyle inboundProductStyle) {
        inboundProductStyle.setId(id);
        boolean result = inboundProductStyleService.updateInboundProductStyleById(inboundProductStyle);
        if (result) {
            return new ResponseEntity<>(true, HttpStatus.OK);
        } else {
            return new ResponseEntity<>(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    // 根据入库产品样式编号删除样式信息
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteInboundProductStyleById(@PathVariable Integer id) {
        boolean result = inboundProductStyleService.deleteInboundProductStyleById(id);
        if (result) {
            return new ResponseEntity<>(true, HttpStatus.OK);
        } else {
            return new ResponseEntity<>(false, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}